import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

//常量路由
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "项目首页", icon: "el-icon-s-help" }
      }
    ]
  }
];

//异步路由
export const allAsyncRoutes = [
  //权限数据管理相关的路由
  {
    name: "Acl",
    path: "/acl",
    component: Layout,
    redirect: "/acl/user/list",
    meta: {
      title: "权限管理",
      icon: "el-icon-lock"
    },
    children: [
      {
        name: "User",
        path: "user/list",
        component: () => import("@/views/acl/user/list"),
        meta: {
          title: "用户管理"
        }
      },
      {
        name: "Role",
        path: "role/list",
        component: () => import("@/views/acl/role/list"),
        meta: {
          title: "角色管理"
        }
      },
      {
        name: "RoleAuth",
        path: "role/auth/:id",
        component: () => import("@/views/acl/role/roleAuth"),
        meta: {
          activeMenu: "/acl/role/list",
          title: "角色授权"
        },
        hidden: true
      },
      {
        name: "Permission",
        path: "permission/list",
        component: () => import("@/views/acl/permission/list"),
        meta: {
          title: "菜单管理"
        }
      }
    ]
  },
  //商品商家管理路由
  {
    path: "/seller",
    name: "OrderList",
    component: Layout,
    meta: { title: "商家信息管理 ", icon: "el-icon-s-shop" },
    children: [
      {
        path: "/brand",
        name: "Refund",
        component: () => import("@/views/seller/brand/index"),
        meta: { title: "卖家信息", icon: "el-icon-crop" }
      },
      {
        path: "/details",
        name: "ActivityRule",
        component: () => import("@/views/seller/details/index"),
        meta: { title: "商品详情", icon: "el-icon-s-promotion" }
      },
      {
        path: "/attribute",
        name: "Coupon",
        component: () => import("@/views/seller/order/index"),
        meta: { title: "订单管理", icon: "el-icon-setting" }
      }
    ]
  },
  // 用户管理路由
  {
    path: "/user",
    name: "User",
    component: Layout,
    meta: { title: "用户信息管理", icon: "el-icon-crop" },
    children: [
      {
        path: "/assess",
        name: "ClientUser",
        component: () => import("@/views/user/assess/index"),
        meta: { title: "用户评价", icon: "el-icon-setting" }
      },
      {
        path: "/info",
        name: "Course",
        component: () => import("@/views/user/info/index"),
        meta: { title: "用户信息", icon: "el-icon-s-promotion" }
      }
    ]
  }
];

//404
export const anyRoute = { path: "*", redirect: "/404", hidden: true };

const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
